package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * 集合的排序
 */
public class SortString {
    public static void main(String[] args) {
        List<String>list=new ArrayList<>();
        list.add("白富美23");
        list.add("高富帅1");
        list.add("矮矬穷456");

        //自定义排序规则：
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o2.length()-o1.length();
            }
        });
        System.out.println("list = " + list);






















        /*
        List<String>list=new ArrayList<>();
        list.add("jack");
        list.add("rose");
        list.add("tom");
        list.add("jerry");
        list.add("black");
        list.add("Kobe");
        System.out.println("list = " + list);


        //英文对应首字母的ASCII码
        //首字母相同比较第二个
        Collections.sort(list);
        System.out.println("list排序后 = " + list);

         */


    }
}
